package com.shanks.framework.mq.data.mybatis.repository;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.shanks.framework.mq.data.mybatis.mapper.MessageConsumeRecordMapper;
import com.shanks.framework.mq.domain.MQMessage;
import com.shanks.framework.mq.model.MessageConsumeRecordPO;
import com.shanks.framework.mq.repository.MessageConsumeRecordRepository;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class MessageConsumeRecordRepositoryImpl implements MessageConsumeRecordRepository {

    @Resource
    private MessageConsumeRecordMapper messageConsumeRecordMapper;

    @Override
    public Boolean selectByMessage(MQMessage mqMessage) {
        return messageConsumeRecordMapper.selectList(Wrappers.lambdaQuery(MessageConsumeRecordPO.class)
                .eq(MessageConsumeRecordPO::getMsgTopic, mqMessage.getTopic())
                .eq(MessageConsumeRecordPO::getMsgTag, mqMessage.getTags())
                .eq(MessageConsumeRecordPO::getMsgKey, mqMessage.getKey())).size() > 0;
    }

    @Override
    public Boolean selectByCheckCode(String checkCode) {
        return messageConsumeRecordMapper.selectList(Wrappers.lambdaQuery(MessageConsumeRecordPO.class)
                .eq(MessageConsumeRecordPO::getCheckcode, checkCode)).size() > 0;
    }

    @Override
    public void insert(MessageConsumeRecordPO messageConsumeRecordPO) {
        messageConsumeRecordMapper.insert(messageConsumeRecordPO);
    }
}
